package org.snail.employee.controller;

import org.apache.log4j.Logger;
import org.snail.employee.bean.AddressCondition;
import org.snail.employee.service.impl.AddressServiceImpl;
import org.snail.exception.JsonResult;
import org.snail.employee.service.AddressService;
import org.snail.employee.bean.AddressDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

/**
 * Created by WJ on 2017/12/12.
 */
@Controller
@RequestMapping("address")
public class AddressController {

    private static final Logger LOGGER =  Logger.getLogger(AddressController.class);

    @Autowired
    private AddressServiceImpl addressServiceImpl;

    /*
     * 通过流的方式上传文件
     * @RequestParam("file") 将name=file控件得到的文件封装成CommonsMultipartFile 对象
     */

    @RequestMapping("insertAddress")
    @ResponseBody
    public JsonResult insertAddress(@RequestBody List<AddressDO> addressDOList) {
        JsonResult result = addressServiceImpl.insertAddressList(addressDOList);
        return result;
    }

    @RequestMapping("deleteAddress")
    @ResponseBody
    public JsonResult deleteAddress(@RequestBody List<AddressCondition> addressDOList) {
        JsonResult result = addressServiceImpl.deleteAddress(addressDOList);
        return result;
    }

    @RequestMapping("saveTestAttGroup")
    @ResponseBody
    public JsonResult saveTestAttGroup() {
        addressServiceImpl.testAddress();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData("插入测试数据成功！");
        return jsonResult;
    }
}
